package org.chispa.api.domain;

import java.util.HashMap;
import java.util.Map;

import org.chispa.api.util.PropertyLoader;

/**
 * @author  bgabor
 */
public class DomainRetrieverFactory {
	
	private DomainRetrieverFactory(){};
	
	private static Map<String,DomainRetriever> retrievers;
	
	/**
	 * @uml.property  name="num_ret"
	 * @uml.associationEnd  
	 */
	private static NumberRetriever num_ret;
	
	static{
		retrievers=new HashMap<String,DomainRetriever>();
		num_ret=new RestfulNumberRetriever();
		//num_ret=new MockedNumberRetriever();
	}
	
	public synchronized static DomainRetriever getInstance(DomainCryptoListener... list)
	{
		String uuid=PropertyLoader.getProperty(DomainRetrieverFactory.class, "uuid");
		return getInstance(uuid,list);
	}

	
	public synchronized static DomainRetriever getInstance(String uuid,DomainCryptoListener... list){
		DomainRetriever retriever=retrievers.get(uuid);
		if(retriever==null)
		{
			if(list.length==0)
				retriever=new SimpleDomainRetriever(num_ret,uuid);
			else
				retriever=new SimpleDomainRetriever(num_ret, uuid,list[0]);
			retrievers.put(uuid, retriever);
		}
		else if(list.length!=0)
			retriever.setDomainListener(list[0]);
		return retriever;
	}

}
